package com.china.school.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanDefinitionRegistryPostProcessorTest implements BeanDefinitionRegistryPostProcessor {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("BeanDefinitionRegistryPostProcessorTest.xml");
        System.out.println(ctx.getBean("beanDefinitionRegistryPostProcessorTest"));
        System.out.println(ctx.getBean("user"));

    }
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
        rootBeanDefinition.setBeanClassName("com.china.school.pojo.User");
        beanDefinitionRegistry.registerBeanDefinition("user",rootBeanDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    }
}
